package cn.tanglong.lasting;

import cn.tanglong.mq.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

public class Producer06 {
    // 交换机名称
    public static final String EXCHANGE_LASTING = "EXCHANGE_LASTING";

    public static void main(String[] args) throws Exception {
            //获取连接
        Connection connection = ConnectionUtil.getConnection();
            //创建与Exchange的通道，每个连接可以创建多个通道，每个通道代表一个会话任务
        Channel channel = connection.createChannel();

        // 创建交换机 交换机名字 类型
        channel.exchangeDeclare(EXCHANGE_LASTING, BuiltinExchangeType.TOPIC,true);
        // 交换机名称为EXCHANGE_LASTING ， 类型为error 开启持久化 信息名称为啊哈
        channel.basicPublish(EXCHANGE_LASTING, "error", MessageProperties.PERSISTENT_TEXT_PLAIN, "error!!!!！".getBytes());

        channel.basicPublish(EXCHANGE_LASTING, "info",  MessageProperties.PERSISTENT_TEXT_PLAIN, "info!!!!！".getBytes());

        channel.basicPublish(EXCHANGE_LASTING, "debug", MessageProperties.PERSISTENT_TEXT_PLAIN, "debug!!!!！".getBytes());

        System.out.println("使用成功！");
    }
}
